package com.epam.task.oop.medicines;

import com.epam.task.oop.Characters.ExtendedToRecipe;
import com.epam.task.oop.Run.MyLogger;
import org.apache.log4j.Logger;

import java.io.Serializable;

public abstract class Product implements Comparable, Serializable, Cloneable, ExtendedToRecipe {
    public static final Logger log = Logger.getLogger(Product.class);
    private static final long serialVersionUID = 1L;
    private int id;
    private String name;
    private String manufacturer;
    private String dateSalesStart;
    private int count;
    private float price;

    public Product(String name, String manufacturer, String dateSalesStart,
                   int count, float price, int id) {
        MyLogger.getLoggerConfiguration();
        this.name = name;
        this.manufacturer = manufacturer;
        this.dateSalesStart = dateSalesStart;
        this.count = count;
        this.price = price;
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public String getDateSalesStart() {
        return dateSalesStart;
    }

    public void setDateSalesStart(String dateSalesStart) {
        this.dateSalesStart = dateSalesStart;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public abstract String toString();

    @Override
    public int hashCode() {
        return (int) (31 * id + count
                + ((name == null) ? 0 : name.hashCode())
                + ((manufacturer == null) ? 0 : manufacturer.hashCode())
                + ((dateSalesStart == null) ? 0 : dateSalesStart.hashCode())
                + Float.floatToIntBits(price));
    }

    @Override
    public boolean equals(Object obj) {

        if (this == obj)
            return true;
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            Product temp = (Product) obj;
            return this.id == temp.id && name.equals(temp.name)
                    && this.count == temp.count && manufacturer.equals(temp.manufacturer)
                    && dateSalesStart.equals(temp.dateSalesStart)
                    && (Float.floatToIntBits(price) != Float.floatToIntBits(temp.price));
        } else
            return false;
    }

    @Override
    public int compareTo(Object object) {
        if (!(object instanceof Product)) {
            return 0;
        }
        Product pp = (Product) object;
        int result = (int) (pp.price - this.price);
        if (result != 0) {
            return (int) result / Math.abs(result);
        }
        return 0;
    }


    public abstract float countCost();

}
